package org.example.MVC;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

@Controller     //该注解可以将普通的类声明成Spring MAC的处理器类，
public class UserController {
    @RequestMapping("/testUser")
    public String testUser(){
        return "order";
    }
    @RequestMapping("/findOrderWithUser")
    public void findOrderWithUser(User user){
        String username = user.getUsername();
        String orderId = user.getOrder().getOrderId();
        System.out.println("username = "+username+"\norderId = "+orderId);
    }

    @RequestMapping("/testOrders")
    public String testOrders(){
        return "orders";
    }
    @RequestMapping("/showOrders")
    public void showOrders(Userlist user){
        List<Order> orders = user.getOrders();
        List<String> addressList = user.getAddress();
        System.out.println("订单：");
        for(int i=0;i<orders.size();i++){
            Order order = orders.get(i);
            String address = addressList.get(i);
            System.out.println("订单Id:"+order.getOrderId());
            System.out.println("订单配送地址:"+address);
        }
    }

    @RequestMapping("/testoderInfor")
    public String testoderInfor(){
        return "order_info";
    }
    @RequestMapping("/oderInfor")
    public void getOrderInfo(OrderMap orderMap){
        String orderId = orderMap.getOrderId();
        HashMap<String,Product> orderInfo = orderMap.getProductInfo();
        Set<String> keys = orderInfo.keySet();
        System.out.println("订单id:"+orderId);
        System.out.println("订单商品信息:");
        for(String key:keys){
            Product product = orderInfo.get(key);
            String proId = product.getProId();
            String proName = product.getProName();
            System.out.println(key+"类~"+"商品id:"+proId+",商品名称:"+proName);
        }
    }
}
